#include "time.h"
#include "lcd.h"

unsigned char xdata hours, minutes, seconds;
unsigned char time_str[9];

void sleep(){
	PCON |= 0x01;                   // set IDLE bit 
	PCON = PCON;  
}

char* get_time_str(){
	time_str[0] = ((hours / 10) | 0x30);
	time_str[1] = ((hours % 10) | 0x30);
	time_str[2] = ':';
	time_str[3] = ((minutes / 10) | 0x30);
	time_str[4] = ((minutes % 10) | 0x30);
	time_str[5] = ':';
	time_str[6] = ((seconds / 10) | 0x30);
	time_str[7] = ((seconds % 10) | 0x30);
	time_str[8] = '\0';
	return &time_str;
}

void TIMER3_ISR() interrupt 14 {
	float delta;
	TMR3CN &= 0x3F;
	
	seconds++;
	
	if(seconds == 60){
		minutes++;
		seconds = 0;
		if(minutes == 60){
			hours++;
			minutes = 0;
			/*
			if(hours == 24){
				hours = 0;
			}
			*/
		}
	}
	//dD = dV / dT
	if(curr_speed > 3 && prev_speed > 3){
		delta = ((curr_speed + prev_speed) / 2.0f) / 3600; //miles per second
		trip += delta;
		odometer  += delta;
	}

}